package com.mexico.inloancash.dialog;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.mexico.inloancash.R;
import com.mexico.inloancash.india_interfacedai.IndiaChooseAddressInterface;
import com.mexico.inloancash.ui.WheelView;

import java.util.List;

public class mIndiaChooseDialog extends Dialog {
    private TextView sure;
    private TextView cancel;
    private Context context;
    private WheelView wheelView;
    private TextView title;
    private String titleName;
    private IndiaChooseAddressInterface anInterface;
    private List<String> list;
    private String type;

    public mIndiaChooseDialog(@NonNull Context context, IndiaChooseAddressInterface anInterface
            , String titleName, List<String> list, String type) {
        super(context, R.style.MyDialog);
        this.context = context;
        this.titleName = titleName;
        this.anInterface = anInterface;
        this.type = type;
        this.list = list;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.india_activity_choose_view_type_layout_dialog);
        Window win = getWindow();
        win.setGravity(Gravity.BOTTOM);

        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);
        setCanceledOnTouchOutside(false);
        cancel = findViewById(R.id.cancel);
        sure = findViewById(R.id.sure);
        wheelView = findViewById(R.id.wheel);
        title = findViewById(R.id.title);
        title.setText(titleName);
        if (null != list && list.size() > 0) {
            wheelView.setDataWithSelectedItemIndex(list, 0);
        }
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                anInterface.choose(type, list.get(wheelView.getSelectedItemIndex()));
                dismiss();
            }
        });

    }
}
